<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/4/13
  Time: 18:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body onload="load()">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <%--    <div class="layui-row">--%>
    <%--        <form class="layui-form layui-col-md12 x-so">--%>

    <%--            <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">--%>
    <%--            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>--%>
    <%--        </form>--%>
    <%--    </div>--%>
    <xblock>

        <button class="layui-btn"
                onclick="x_admin_show('添加职位','${pageContext.request.contextPath}/job/addJobPage')"><i
                class="layui-icon"></i>添加职位
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span id="countData"></span> 条 &nbsp;&nbsp;共有<span id="countPage"></span>页</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>英文名</th>
            <th>中文名</th>
            <th>操作</th>
        </thead>

        <tbody id="tb">

        <%--显示数据--%>

        </tbody>
    </table>
<%--    <div class="page">--%>
<%--        <div>--%>
<%--            <button  type="button" class="prev" onclick="pre()">&lt;&lt;</button>--%>

<%--            <span class="current">1</span>--%>

<%--            <button  type="button" class="next" onclick="next()" >&gt;&gt;</button>--%>
<%--        </div>--%>
<%--    </div>--%>

</div>
<script>


    /*职位-删除*/
    function member_del(obj) {
        let is = confirm("你确定要删除吗？");
        if (is) {
            let id = $(obj).parent().parent().find("td").eq(1).text();
            console.log(id)
            $.ajax({
                url: "${pageContext.request.contextPath}/job/deleteBysId",
                type: "get",
                data: {"id": id},
                dataType: "json",
                success: function (data) {
                    alert(data.info);
                    load();//回显删除完之后的数据
                }
            });
        }
    }
</script>
</body>
<script>
    function load() {
        $.ajax({
            url: "${pageContext.request.contextPath}/job/allJob",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (typeof (data.info) == "string") {
                    $("#tb").html("");
                } else {
                    var html = "";
                    for (var i = 0; i < data.info.length; i++) {
                        html += "<tr>" +
                            "<td>" +
                            "   <div class=\"layui-unselect layui-form-checkbox\" lay-skin=\"primary\" data-id='2'><i class=\"layui-icon\">&#xe605;</i></div>" +
                            "</td>" +
                            "<td>" + data.info[i].jId + "</td>" +
                            "<td>" + data.info[i].jName + "</td>" +
                            "<td>" + data.info[i].jNameCh + "</td>" +
                            "<td class='td-manage'>" +
                            "        <a title=\"编辑职位\" onclick=\"x_admin_show('修改职位','${pageContext.request.contextPath}/permission/permissionEdit')\"href=\"javascript:;\">\n" +
                            "                    <i class=\"layui-icon\">&#xe642;</i>\n" +
                            "                </a>" +
                            " <a title=\"删除职位\" onclick=\"member_del(this,'要删除的id')\" href=\"javascript:;\">\n" +
                            "                <i class=\"layui-icon\">&#xe640;</i>\n" +
                            "              </a>" +
                            "</td>" +
                            //    this指当前标签，这里就指向 button标签（写在哪个标签就是哪个标签）
                            "</tr>";
                    }
                    $("#tb").html(html);
                    $("#countData").text(data.info.length);
                }
            }
        })
    }
</script>
</html>
